package com.zhs.gccs.dialog;

import android.content.Context;

import android.view.LayoutInflater;
import android.view.View;


import androidx.appcompat.app.AlertDialog;

import com.zhs.gccs.R;

/**
 * Created by heyang on 2016/12/28.
 */

public class SimpleLoadDialog {
    private AlertDialog alertDialog = null;

    private Context context;
    private boolean cancelable;


    public SimpleLoadDialog(Context context, boolean cancelable) {
        super();
        this.context = context;
        this.cancelable = cancelable;
    }

    public void show() {
        if(alertDialog == null){
            View dialogView = LayoutInflater.from(context).inflate(
                    R.layout.dialog_loading, null);
            alertDialog = new AlertDialog
                    .Builder(context, R.style.dialog)
                    .setCancelable(cancelable)
                    .show();
            alertDialog.setContentView(dialogView);
            alertDialog.setCanceledOnTouchOutside(cancelable);
        }
        alertDialog.show();
    }

    public void dismiss() {
        if(alertDialog != null && alertDialog.isShowing()){
            alertDialog.dismiss();
            alertDialog = null;
        }
    }
}
